import { Component, OnInit, Output, EventEmitter } from '@angular/core';
import { NavParams, Events, ModalController, Platform } from '@ionic/angular';
import { QRScannerModal } from '@modals/qr-scanner/qr-scanner';
import { TypeSelectModal } from '@modals/wire-less/type-select/type-select';

@Component({
    selector: 'wire-less',
    templateUrl: 'wire-less.html',
    styleUrls: ['wire-less.scss']
})
export class WirelessModal implements OnInit {
    inspeed;
    public viewData = {
        scanStack: false,
        scanConfig: false,
        speeds: {
            title: '',
        },
        outRange: false,
        channel: '',
    };

    constructor(public navParams: NavParams, public events: Events, public modalCtrl: ModalController,
        public platform: Platform) {
        // this.platform.backButton.subscribe(res => {
        //     this.closeModal();
        // })
    }

    ngOnInit() {
        this.inspeed = '';
        this.viewData.speeds.title = '请选择空中速率';
    }
    async scan() {
        const videoModal = await this.modalCtrl.create({
            component: QRScannerModal
        });
        videoModal.present();
    }

    async SpeedSelect() {
        const data = {
            title: this.viewData.speeds.title,
            value: this.inspeed
        };
        const modalNext = await this.modalCtrl.create({
            component: TypeSelectModal,
            componentProps: data
        });
        modalNext.present();
        const inspeed = await modalNext.onDidDismiss();
        this.inspeed = inspeed.data;
        console.log(this.inspeed)
    }

    send() {
        if (!this.viewData.scanStack) {
            console.log('数据栈未扫描!');
        } else if (!this.viewData.scanConfig) {
            console.log('无线模块未扫描!');
        } else if (this.viewData.outRange || (this.viewData.channel === null)) {
            console.log('无线频道未填写！');
        } else {
            console.log('空中速率未选择!');
        }
    }

    closeModal() {
        this.modalCtrl.dismiss();
    }
}
